package com.itheima.pinda.service.impl;

import com.itheima.pinda.entity.AddressRule;
import com.itheima.pinda.service.DroolsRulesService;

import java.math.BigDecimal;

public class DroolsRulesServiceImpl implements DroolsRulesService {


    @Override
    public String calcFee(AddressRule addressRule) {

        // 续重
        BigDecimal subtract = new BigDecimal(addressRule.getTotalWeight()).subtract(new BigDecimal(addressRule.getFirstWeight()));

        BigDecimal multiply = new BigDecimal(addressRule.getContinuedFee()).multiply(subtract.setScale(0,BigDecimal.ROUND_UP));

        // 金额
        BigDecimal amount = new BigDecimal(addressRule.getFirstFee()).add(multiply);

        return amount.toString();
    }
}
